public class Main9 {
    public static void main(String[] args) {
        String[] arr1 = {"1", "2", "3"};
        String[] arr2 = {"4", "5", "6"};
        String[] result_union = union(arr1, arr2);
        System.out.println("并集的结果如下：");

        for (String str : result_union) {
            System.out.println(str);
        }
    }


    // 求两个字符串数组的并集，利用set的元素唯一性
    public static String[] union(String[] arr1, String[] arr2) {
        java.util.Set<String> set = new java.util.HashSet<String>();

        java.util.Collections.addAll(set, arr1);

        java.util.Collections.addAll(set, arr2);

        String[] result = {};

        return set.toArray(result);
    }
}
